class TestOneSidePlatform extends Test
{
	public m_radius:number;
	public m_top:number;
	public m_bottom:number;
	public m_state:number;
	public m_platform:Box2D.Dynamics.b2Fixture;
	public m_character:Box2D.Dynamics.b2Fixture;

	private e_unknown:number = 0;
	private e_above:number = 1;
	private e_below:number = 2;

	public constructor(sprite:DebugDraw) 
	{
		super(sprite);

		let bd:Box2D.Dynamics.b2BodyDef;
		let body:Box2D.Dynamics.b2Body;

		//platform
		{
			bd = new Box2D.Dynamics.b2BodyDef;
			bd.position.Set(10.0,10.0);
			body = this.m_world.CreateBody(bd);

			var polygon:Box2D.Collision.Shapes.b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape.AsBox(3.0, 0.5);
			this.m_platform = body.CreateFixture2(polygon);

			this.m_bottom = bd.position.y + 0.5;
			this.m_top = bd.position.y - 0.5;

		}
		//actor
		{
			bd = new Box2D.Dynamics.b2BodyDef();
			bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
			bd.position.Set(300 / this.m_physScale, 300 / this.m_physScale);
			body = this.m_world.CreateBody(bd);

			this.m_radius = 15 / this.m_physScale;
			let circle:Box2D.Collision.Shapes.b2CircleShape = new Box2D.Collision.Shapes.b2CircleShape(this.m_radius);
			this.m_character = body.CreateFixture2(circle, 1.0);
			this.m_state = this.e_unknown;
		}
		this.m_world.SetContactListener(new ContactListener(this));
	}
}

class ContactListener extends Box2D.Dynamics.b2ContactListener
{
	private test:TestOneSidePlatform;

	public constructor(test:TestOneSidePlatform){
		super();
		this.test = test
	}

	public PreSolve(contact:Box2D.Dynamics.Contacts.b2Contact, oldManifold:Box2D.Collision.b2Manifold):void
	{
		let fixtureA:Box2D.Dynamics.b2Fixture = contact.GetFixtureA();
		let fixtureB:Box2D.Dynamics.b2Fixture = contact.GetFixtureB();
		if(fixtureA != this.test.m_platform && fixtureA != this.test.m_character)
		{
			return;
		}
		if(fixtureB != this.test.m_platform && fixtureB != this.test.m_character)
		{
			return;
		}

		let position:Box2D.Common.Math.b2Vec2 = this.test.m_character.GetBody().GetPosition();
		if(position.y > this.test.m_top)
		{
			contact.SetEnabled(false);
		}
	}
}